﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using ConsumerClient.ServiceReference1;

namespace ConsumerClient
{
    /// <summary>
    /// Interaction logic for UpdateUser.xaml
    /// </summary>
    public partial class UpdateUser : Window
    {
        public WCFUser User;
        private PlanRouteServiceClient client;

        public UpdateUser(WCFUser user, PlanRouteServiceClient client)
        {
            this.client = client;
            InitializeComponent();
            this.User = user;
            txtAddress1.Text = user.AddressLine1;
            txtAddress2.Text = user.AddressLine2;
            txtEmail.Text = user.Email;
            txtName.Text = user.Name;
            txtPhone.Text = user.Phone;
            txtZipCode.Text = user.ZipCodeCity.ZipCode.ToString();
            txtZipCodeCity.Text = user.ZipCodeCity.City;
        }

        private void Click_Cancel(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
            //this.Close();
        }

        private async void Click_Update(object sender, RoutedEventArgs e)
        {
            btn_cancel.IsEnabled = false;
            btn_update.IsEnabled = false;
            
            User.AddressLine1 = txtAddress1.Text;
            User.AddressLine2 = txtAddress2.Text;
            User.Email = txtEmail.Text;
            User.Name = txtName.Text;
            User.Phone = txtPhone.Text;
            User.ZipCodeCity.ZipCode = int.Parse(txtZipCode.Text);
            User.ZipCodeCity.City = txtZipCodeCity.Text;
            
            Task<WCFUser> getUser = client.updateUserAsync(User);
            User = await getUser;
            DialogResult = true;
            //this.Close();
        }
    }
}
